import React, { Component } from 'react'
import {connect} from 'react-redux'
import {NavBar, InputItem, TextareaItem, Button} from 'antd-mobile'
import { Redirect } from 'react-router-dom'

import HeaderSlector from '../../components/headerSlector/HeaderSlector'
import {updateUser } from '../../redux/actions'
class DashenInfo extends Component {

    state = {
        header: '',
        post: '',
        info: ''
    }

    // 更新header状态   子组件修改父组件的状态
    setHeader = (header) =>{
        this.setState({
            header
        })
    }

    handleChange = (name, value)=>{
        this.setState({
            [name]: value
        })
    }
    save = ()=>{
        this.props.updateUser(this.state)
    }
    render() {
        // 如果信息已经完善，定位到对应主界面
        const {header, type} = this.props.user
        if(header){
            let path = type==='dashen' ? '/boss' : '/dashen'
            return <Redirect to={path}/>
        }
        return (
            <div>
                <NavBar>dashen信息完善</NavBar>
                <HeaderSlector setHeader={this.setHeader}/>
                <InputItem placeholder='请输入求职岗位' onChange={(val)=>{this.handleChange('post', val)}}>求职职位: </InputItem>
                <TextareaItem title="个人介绍:" rows={3} onChange={(val)=>{this.handleChange('info', val)}} />
                <Button type='primary' onClick={this.save}>保&nbsp;&nbsp;存</Button>
            </div>
        )
    }
}

export default connect(
    state =>({user: state.user}),
    {updateUser}
)(DashenInfo)